use std::str::FromStr;
use clap::Parser;

#[derive(Debug, Clone)]
enum OperateHandler {
    Crawl,
}

impl FromStr for OperateHandler {
    type Err = String;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s.to_lowercase().as_str() {
            "crawl" => Ok(Self::Crawl), 
            _ => Err("没有这个操作".to_string())
        }
    }
}

impl OperateHandler {
    fn handle(&self) {
        match self {
            Self::Crawl => (),
        }
    }
}

#[derive(Debug, Clone)]
enum ObjectHandler {
    Bili,
}

impl FromStr for ObjectHandler {
    type Err = String;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s.to_lowercase().as_str() {
            "bili" => Ok(Self::Bili),
            _ => Err("没有这个能力".to_string()),
        }
    }
}

#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
pub struct Args {
    operate: Option<OperateHandler>,
    object: Option<ObjectHandler>,
    #[arg(long)]
    target: Option<Vec<String>>,
}

impl Args {
    pub fn handle_args(&self) {
        println!("{:?}", self);
    }
}
